package boggle;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.BorderFactory;

public class JBoggleButton extends JButton{
	private String str;    // the str for this button
	private int x;         // x coordinate of this button
	private int y;         // y coordinate of this button
	private int State;     // current state of Boggle button
	public static final int STATE_UNAVAILABLE = 0;  
	public static final int STATE_AVAILABLE   = 1;  
	public static final int STATE_SELECTED    = 2;
	private static final Border UNAVAILABLE_BORDER = BorderFactory.createLineBorder(Color.GRAY, 5, true);
	private static final Border AVAILABLE_BORDER   = BorderFactory.createLineBorder(Color.GREEN, 5, true);
	private static final Border SELECTED_BORDER    = BorderFactory.createLineBorder(Color.RED, 5, true);
	
	
	public JBoggleButton(String str, int x, int y) {
		super(str);
		this.str = str;
		this.x = x;
		this.y = y;	
		setButtonState(STATE_AVAILABLE);
		setFont(new Font("sans-serif",Font.BOLD, 40));
	}
	
	/**
	 * get row index(or x index) of button
	 * @return, row index (or x index)
	 */
	public int getBoardX() { return x; }
	
	public int getBoardY() { return y; }
	
	public String getButtonString() { return str; }
	
	public int getButtonState() { return State; }
	
	public void setButtonState(int State) {
		if (State == STATE_UNAVAILABLE) {
			setEnabled(false);
			setBorder(UNAVAILABLE_BORDER);
		}
		else if (State == STATE_AVAILABLE) {
			setEnabled(true);
			setBorder(AVAILABLE_BORDER);
		}
		else {
			setEnabled(true);
			setBorder(SELECTED_BORDER);
		}
	}
	
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// Test the button
		JBoggleButton bt = new JBoggleButton("Qu",0,0);
		JBoggleButton bt2 = new JBoggleButton(" T ",0,0);
		JBoggleButton bt3 = new JBoggleButton(" S ",0,0);
		bt2.setButtonState(JBoggleButton.STATE_SELECTED);
		bt3.setButtonState(JBoggleButton.STATE_UNAVAILABLE);
		JFrame theFrame = new JFrame("Button");
		theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		theFrame.setLayout(new FlowLayout());
		
		//theFrame.add(new JLabel("Hello World."));
		//theFrame.add(new JTextField(15));
		//theFrame.add(new JSlider(JSlider.HORIZONTAL,0,100,50));
		theFrame.add(bt);
		theFrame.add(bt2);
		theFrame.add(bt3);
		theFrame.pack();
		theFrame.setVisible(true);

	}

}
